//
//  THJOutGoldVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/8/10.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJOutGoldVC.h"

@interface THJOutGoldVC ()

@end

@implementation THJOutGoldVC

- (void)viewDidLoad {
    [super viewDidLoad];
   
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:self.flag];
    }else{
        [self setNavBarWithTitle:self.flag];
    }
    [self getData];
    if([self.flag isEqual:@"余额"]){
        self.view1.hidden = YES;
        self.view2.hidden = YES;
        self.btn.hidden = YES;
    }
    //    any additional setup after loading the view from its nib.
}
- (IBAction)sureBtnAction:(id)sender {
    
    if(self.tf1.text.length == 0){
        [self HUDShowMsg:@"输入金额" AfterDelayDimiss:1];
        return;
    }else if(self.tf2.text.length == 0){
        [self HUDShowMsg:@"输入支付密码" AfterDelayDimiss:1];
        return;
    }
    
    NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
    NSString * money = [RSA encryptString:self.tf1.text publicKey:RSA_PubKey];
    NSString * pwd = [RSA encryptString:self.tf2.text publicKey:RSA_PubKey];
    [self SVHUDShow];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=pay_seller_ok" parameters:@{
                                                                                                        @"mobile":mobile,
                                                                                                        @"type":@"ios",
                                                                                                        @"pwd":pwd,
                                                                                                        @"money":money
                                                                                                } callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"出金--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
           [self HUDShowMsg:@"出金成功" AfterDelayDimiss:1];
            self.tf1.text = @"";
            self.tf2.text = @"";
            [self getData];
        }else{
            NSString * tip = [RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey];
            [self HUDShowMsg:tip AfterDelayDimiss:2];
        }
    }];
}

-(void)getData{
    [self SVHUDShow];
    NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=hjb_dj" parameters:@{@"mobile":mobile,@"type":@"ios"} callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"出金--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            NSLog(@"money-%@",[RSA decryptString:receiveData[@"data"][@"money"] publicKey:RSA_PubKey]);
            NSLog(@"ymoney-%@",[RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey]);
            NSLog(@"nmoney-%@",[RSA decryptString:receiveData[@"data"][@"nMoney"] publicKey:RSA_PubKey]);
            self.lab2.text = [RSA decryptString:receiveData[@"data"][@"money"] publicKey:RSA_PubKey];
            self.lab1.text = [RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey];
            self.lab3.text = [RSA decryptString:receiveData[@"data"][@"nMoney"] publicKey:RSA_PubKey];
        }else{
            [self HUDShowMsg:[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey] AfterDelayDimiss:1];
        }
    }];
}

@end
